import java.util.ArrayList;

public class Job
{
	private int release;
	private int time;	//Computation time
	private int initTime;
	private int response;
	private int start;
	private ArrayList<Integer> execTime;
	private ArrayList<Pair> mergedExecTime = null;
	
	private Task owner;
	
	public Job()
	{
		start = -1;
		execTime = new ArrayList<Integer>();
	}
	
	public String toString()
	{
		return "#Job: Release time " + release + " time " + getTime() + " response " + getResponse() + " initTime " + getInitTime() + " " + owner.toString();
	}
	
	private ArrayList<Pair> mergeExecTime(ArrayList<Integer> execTime)
	{
		ArrayList<Pair> pairs = new ArrayList<Pair>();
		if(execTime.size() > 0)
		{
			int position = 0;
			
			Pair p = new Pair(execTime.get(position), execTime.get(position));
			
			for(; position < execTime.size(); )
			{
				position = scan(execTime, p, position + 1);
				pairs.add(p);
				
				if(position < execTime.size())
				{
					p = new Pair(execTime.get(position), execTime.get(position));
				}
			}
		}
		
		return pairs;
	}
	
	private static int scan(ArrayList<Integer> execTime, Pair pair, int position)
	{
		int i = position;
		for(; i < execTime.size() && execTime.get(i) == pair.getFinish() + 1; i++)
		{
			pair.setFinish(execTime.get(i));
		}
		
		return i;
	}
	
	public int getRelease() 
	{
		return release;
	}
	public void setRelease(int release) 
	{
		this.release = release;
	}
	public int getTime() 
	{
		return time;
	}
	public void setTime(int time) 
	{
		this.time = time;
	}
	public int getResponse() 
	{
		return response;
	}
	public void setResponse(int response) 
	{
		this.response = response;
	}
	public int getStart() 
	{
		return start;
	}
	public void setStart(int start) 
	{
		this.start = start;
	}
	public Task getOwner() 
	{
		return owner;
	}
	public void setOwner(Task owner) 
	{
		this.owner = owner;
	}

	public int getInitTime() 
	{
		return initTime;
	}

	public void setInitTime(int initTime) 
	{
		this.initTime = initTime;
	}

	public ArrayList<Integer> getExecTime() {
		return execTime;
	}

	public void setExecTime(ArrayList<Integer> execTime) {
		this.execTime = execTime;
	}
	
	public ArrayList<Pair> getMergedExecTime() 
	{
		if(mergedExecTime == null)
		{
			mergedExecTime = mergeExecTime(execTime);
		}
		return mergedExecTime;
	}

	public void setMergedExecTime(ArrayList<Pair> mergedExecTime) {
		this.mergedExecTime = mergedExecTime;
	}
}

class Pair
{
	private int start = 0;
	private int finish = 0;
	public Pair(){}
	public Pair(int start, int finish)
	{
		this.start = start;
		this.finish = finish;
	}
	public int getStart() {
		return start;
	}
	public void setStart(int start) {
		this.start = start;
	}
	public int getFinish() {
		return finish;
	}
	public void setFinish(int finish) {
		this.finish = finish;
	}
	
	public String toString()
	{
		return "Start: " + start + "; finish: " + finish;
	}
}

